<template>
  <view>
    <nav-bar title="商品订单" backgroundColor="#115BAA" titleColor="#FFF"></nav-bar>
    <you-tabs
			:activeName="tabActive"
      :tabsList="tabsList"
      backgroundColor="#115BAA"
      tabItemColor="#FFF"
      tabActiveColor="#FFF"
      bottomLineColor="#FFF"
      bottomLineWidth="100%"
      lineBorderRadius="0"
      tabActiveSize="30rpx"
      @tabClick="clickTabItem"
		></you-tabs>
    <you-scroll
      :loadingHeight="loadingHeight"
      :mainHeight="scrollHeight"
      :isAllData="isAllData"
      :isRequestSuccess="isRequestSuccess"
      outPaddingTop="30rpx"
      @onRefresh="onRefresh"
      @loadMore="loadMore"
    >
      <template>
        <view v-if="isLoading" class="common-loading">
          <image class="loading-img" :src="baseIconUrl + '/commonIcon/icon_loading.png'" />
          正在加载数据，请稍后......
        </view>
        <view class="common-no-data" v-else-if="!orderList || orderList.length === 0">
          <image class="no-data-img" :src="baseIconUrl + '/commonIcon/icon_no_data.png'" />
          <view class="text">暂无数据</view>
        </view>
        <view v-else>
          <order-list :orderList="orderList" @orderList="freshOrder"></order-list>
        </view>
      </template>
    </you-scroll>
  </view>
</template>

<script>
  import OrderList from '../../components/orderList'
  import { baseImgUrl, baseIconUrl } from '@/config'
  import api_user from '@/api/user'
  export default {
    name: 'OrderList',
    components: { OrderList },
    data() {
      return {
        baseImgUrl,
        baseIconUrl,
				tabActive: null,
        tabsList: [
					{ label: "全部", name: null },
					{ label: "待发货", name: 1 },
					{ label: "配送中", name: 2 },
					{ label: "已收货", name: 3 },
				],
        loadingHeight: '',
        scrollHeight: '',
        isAllData: false,
        isRequestSuccess: false,
        isLoading: false,
        pageNum: 1,
        pageSize: 10,
        total: 0,
        orderList:[]
      }
    },
    onLoad() {
      this.scrollHeight = this.$store.getters.heightData.mainHeight - 48 + 'px'
      this.loadingHeight = this.$store.getters.heightData.mainHeight - 68 + 'px'
      this.getOrderList()
    },
    mounted() {
      
    },

    methods: {
      clickTabItem(active) {
				this.tabActive = active
        this.pageNum = 1
        this.orderList = []
        this.getOrderList()
			},
      getOrderList(){
        const params = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          orderState: this.tabActive
        }
        api_user.orderList(params).then(res => {
          if (res.code !== 200) return
          this.orderList.push(...res.rows)
          this.total = res.total
          this.isRequestSuccess = true
          this.isLoading = false
        })
      },
      //刷新列表
      freshOrder(){
        this.pageNum = 1
        this.orderList = []
        this.getOrderList()
      },
      // 下拉刷新
      onRefresh() {
        this.pageNum = 1
        this.orderList = []
        this.isAllData = false
        this.isRequestSuccess = false
        this.getOrderList()
      },
      // 上拉加载
      loadMore() {
        if (this.orderList.length < this.total) {
          this.pageNum++
          this.isAllData = false
          this.isRequestSuccess = false
          this.getOrderList()
        } else {
          this.isAllData = true
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
</style>
